Skip to content

Add reusable zipper buffers - #65

Open
imlvts wants to merge 1 commit into
Adam-Vandervorst:masterfrom
imlvts:zipper-buffer-reuse
Open

Add reusable zipper buffers#65
imlvts wants to merge 1 commit into
Adam-Vandervorst:masterfrom
imlvts:zipper-buffer-reuse

Conversation

@imlvts

@imlvts imlvts commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

This introduces ZipperBuffer. This allows re-using zipper path and stack Vecs.
Name up for change, don't have a strong preference.

fn ReadZipper::detach(self) -> ZipperBuffer; // saves path
fn ZipperBuffer::attach(self, &map) -> ReadZipper; // restores path
fn ReadZipper::relocate(self, &map) -> ReadZipper; // same path on a different map

detach + attach, relocate preserve the path. might need to change the API so this is explicit.

A few additional non-public API changes to make it work.
descend_to_byte used instead of descend_to to avoid aliased &mut.

@adamv-symbolica

Copy link
Copy Markdown

Nice! I quite like the API and naming.
The ancestor_node thing is a little ugly, but the lifetime tagging makes sense.
What's the motivation for going for a new object, rather than just a "disabled RZ" which is a zero-overhead opaque-type wrapper of a RZ?

@luketpeterson

Copy link
Copy Markdown
Collaborator

I'm ok with the API concept. I'd prefer different names for detach and attach. And I think relocate has some issues.

detach doesn't say enough about what it does. It sounds too fundamental for an optimization like this. We could use the rust idiom for a consuming conversion, i.e. into_buffer or into_zipper_buffer (I prefer the latter). Another option is to make it clear we're destroying the zipper but saving the buffers with salvage_buffer. I think I like into_zipper_buffer.

On attach, same issue. That verb sounds really central to what it does conceptually. Which it isn't. My preference would be variants of PathMap::read_zipper_with_buffer(&self, buffer: ZipperBuffer<V, A>).

ZipperBuffer::into_read_zipper(map: &'map PathMap<V, A>) could work, but. I have a fairly strong preference for read_zipper_with_buffer because it establishes a pattern that could work with ZipperHead methods too. (_unchecked ZH methods are what MORK will really want, I assume)

As far as relocate, my issue is the case as with attach / ZipperBuffer::into_read_zipper It assumes a PathMap so we'd need to create a different API shape for a ZipperHead. And it is basically a convenience. But anyone who is looking for this API wants runtime performance over convenience.

@adamv-symbolica

Copy link
Copy Markdown

I think the most important part not covered there is that you want to take these zippers at a path, you may not have access to the root, nor want to pay the cost of re-descending.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants